package spring.cloud.tasks.api.service;

import spring.cloud.tasks.api.domain.executor.Executor;
import spring.cloud.tasks.api.domain.task.TaskConfiguration;
import spring.cloud.tasks.api.domain.task_executor.TaskExecutor;
import spring.cloud.tasks.api.domain.task_executor.TaskExecutorStatusInfo;
import spring.cloud.tasks.api.domain.task_item.TaskItemExecuteInfo;
import spring.cloud.tasks.api.vo.TaskConfigurationVo;

import java.util.List;
import java.util.Map;

public interface TaskService {

    int getMaxTaskNum() throws RuntimeException;

    boolean taskIncExceeds(String nameSpace, int maxJobNum, int inc) throws RuntimeException;

    void addTask(String nameSpace, TaskConfiguration taskConfiguration, String userId) throws RuntimeException;

    void deleteTask(String nameSpace, String taskId, String userId) throws RuntimeException;

    void enableTask(String nameSpace, String taskId, String userId) throws RuntimeException;

    void disableTask(String nameSpace, String taskId, String userId) throws RuntimeException;

    void runAtOnce(String nameSpace, String taskId, final Map<String, Object> triggeredData) throws RuntimeException;


    void stopAtOnce(String nameSpace, String taskId, final Map<String, Object> triggeredData) throws RuntimeException;

    /**
     * 获取该任务可选择的优先Executor
     */
    List<Executor> getExecutorList(String nameSpace, String taskId) throws RuntimeException;

    void setPreferExecutorIdList(String nameSpace, String taskId, String preferExecutorIdList) throws RuntimeException;


    List<TaskConfiguration> getTaskConfigurationList(String nameSpace) throws RuntimeException;


    List<String> getTaskIdList(String nameSpace) throws RuntimeException;


    TaskConfiguration getTaskConfiguration(String nameSpace, String taskId) throws RuntimeException;


    List<String> getExecutorIdList(String nameSpace, String taskId) throws RuntimeException;

    TaskConfigurationVo getTaskConfigurationVo(String nameSpace, String taskId) throws RuntimeException;

    void updateTaskConfiguration(String nameSpace, TaskConfiguration taskConfiguration) throws RuntimeException;

    List<String> getTaskIdListFromZooKeeper(String nameSpace) throws RuntimeException;

    void updateTaskCronExpression(String nameSpace, String taskId, String cronExpression, String pausePeriodDate, String pausePeriodTime) throws RuntimeException;

    /**
     * 获取任务所分配的executor及先关分配信息。
     */
    List<TaskExecutor> getTaskExecutorList(String nameSpace, String taskId) throws RuntimeException;

    /**
     * 获取JobServer状态信息
     */
    List<TaskExecutorStatusInfo> getTaskExecutorStatusInfoList(String nameSpace, String taskId) throws RuntimeException;


    /**
     * 获取任务运行状态
     */
    List<TaskItemExecuteInfo> getTaskItemExecuteInfoList(String nameSpace, String taskId) throws RuntimeException;


    /**
     * Get the job info by nameSpace and taskId pair.
     *
     * @throws RuntimeException for below scenarios: <ul> <li>nameSpace or taskId is not found (statusCode =
     *                          404)</li> <li>Other exceptions (statusCode = 500)</li> </ul>
     */
    TaskConfiguration getTaskInfo(String nameSpace, String taskId) throws RuntimeException;

    /**
     * Get the jobs info under the nameSpace
     */
    List<TaskConfiguration> getTaskInfoList(String nameSpace) throws RuntimeException;

}
